home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 1 (Walnut Creek)
/
Aminet - June 1993 [Walnut Creek].iso
/
aminet
/
util
/
gnu
/
gnu_smalltalk1_2.lha
/
Class.st
< prev
next >
Wrap
Text File
|
1992-02-15
|
8KB
|
288 lines
"======================================================================
|
| Class Method Definitions
|
======================================================================"
"======================================================================
|
| Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
| Written by Steve Byrne.
|
| This file is part of GNU Smalltalk.
|
| GNU Smalltalk is free software; you can redistribute it and/or modify it
| under the terms of the GNU General Public License as published by the Free
| Software Foundation; either version 1, or (at your option) any later version.
|
| GNU Smalltalk is distributed in the hope that it will be useful, but WITHOUT
| ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
| FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
| details.
|
| You should have received a copy of the GNU General Public License along with
| GNU Smalltalk; see the file COPYING. If not, write to the Free Software
| Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
======================================================================"
"
| Change Log
| ============================================================================
| Author Date Change
| sbb 16 Mar 91 Class creation now separate statement.
|
| sbb 22 Sep 90 Implemented classVarNames and allClassVarNames.
| Implemented sharedPools and allSharedPools.
|
| sbyrne 16 May 90 Improved error checking: you now cannot create a
| subclass of a class whose type is not compatible
| (i.e. non-variable subclass of a variable byte
| class).
|
| sbyrne 16 May 90 Minor changes to support preserving class definitions
| as long as possible (i.e. if you re-invoke the class
| definition method, it tries to re-use the existing
| class if possible).
|
| sbyrne 13 Jan 90 Began experimental addition of actual class
| definitions.
|
| sbyrne 25 Apr 89 created.
|
"
ClassDescription subclass: #Class
instanceVariableNames: 'classVariables sharedPools'
classVariableNames: ''
poolDictionaries: ''
category: nil
!
Class comment:
'I am THE class object. My instances are the classes of the system' !
!Class methodsFor: 'accessing instances and variables'!
addClassVarName: aString
| sym |
sym _ aString asSymbol. "### maybe this should remain a string? "
(classVariables includesKey: sym)
ifTrue: [ ^self error: 'class variable already present' ]
ifFalse: [ classVariables at: sym put: nil ]
!
removeClassVarName: aString
"Removes the class variable from the class, error if not present, or
still in use."
| sym |
sym _ aString asSymbol. "### maybe this should remain a string? "
" ### test for use in sub method "
(classVariables includesKey: sym)
ifTrue: [ classVariables removeKey: sym ]
ifFalse: [ self error: 'class variable not present' ]
!
classPool
^classVariables
!
classVarNames
| superVarNames |
self superclass isNil
ifTrue: [ ^self allClassVarNames ].
superVarNames _ self superclass allClassVarNames.
^(self allClassVarNames) removeAll: superVarNames
!
allClassVarNames
| s |
s _ Set new.
classVariables keysDo: [ :key | s add: key ].
^s
!
addSharedPool: aDictionary
(sharedPools includes: aDictionary)
ifTrue: [ ^self error: 'Attempt to add an already-present shared pool' ].
sharedPools _ sharedPools copyWith: aDictionary
!
removeSharedPool: aDictionary
(sharedPools includes: aDictionary)
ifFalse: [ ^self error: 'Attempt to remove non-existent shared pool' ].
sharedPools _ sharedPools copyWithout: aDictionary
!
sharedPools
| superPools |
self superclass isNil
ifTrue: [ ^self allSharedPools ].
superPools _ self superclass allSharedPools.
^(self allSharedPools) removeAll: superPools
!
allSharedPools
| s |
s _ Set new.
sharedPools do:
[ :sp | s add: (Smalltalk keyAtValue: sp) ].
^s
!
initialize "redefined in children (?)"
^self
!!
!Class methodsFor: 'testing'!
= aClass
"Returns true if the two class objects are to be considered equal."
^name = aClass name
!!
!Class methodsFor: 'instance creation'!
subclass: classNameString
instanceVariableNames: stringInstVarNames
classVariableNames: stringOfClassVarNames
poolDictionaries: stringOfPoolNames
category: categoryNameString
| meta |
KernelInitialized ifFalse: [ ^nil ].
self isVariable
ifTrue: [ ^self error: 'cannot create a non-variable subclass
of a variable class' ].
meta _ self metaclassFor: classNameString.
^meta name: classNameString
environment: Smalltalk
subclassOf: self
instanceVariableNames: stringInstVarNames
variable: false
words: true
pointers: true
classVariableNames: stringOfClassVarNames
poolDictionaries: stringOfPoolNames
category: categoryNameString
comment: nil
changed: nil
!
variableSubclass: classNameString
instanceVariableNames: stringInstVarNames
classVariableNames: stringOfClassVarNames
poolDictionaries: stringOfPoolNames
category: categoryNameString
| meta |
KernelInitialized ifFalse: [ ^nil ].
self isVariable & (self isWords | self isBytes)
ifTrue: [ ^self error: 'cannot create a variable subclass from a
non-pointer variable parent class' ].
meta _ self metaclassFor: classNameString.
^meta name: classNameString
environment: Smalltalk
subclassOf: self
instanceVariableNames: stringInstVarNames
variable: true
words: true
pointers: true
classVariableNames: stringOfClassVarNames
poolDictionaries: stringOfPoolNames
category: categoryNameString
comment: nil
changed: nil
!
variableWordSubclass: classNameString
instanceVariableNames: stringInstVarNames
classVariableNames: stringOfClassVarNames
poolDictionaries: stringOfPoolNames
category: categoryNameString
| meta |
KernelInitialized ifFalse: [ ^nil ].
self isVariable & (self isPointers | self isBytes)
ifTrue: [ ^self error: 'cannot create a word subclass from a non-word
variable parent class' ].
meta _ self metaclassFor: classNameString.
^meta name: classNameString
environment: Smalltalk
subclassOf: self
instanceVariableNames: stringInstVarNames
variable: true
words: true
pointers: false
classVariableNames: stringOfClassVarNames
poolDictionaries: stringOfPoolNames
category: categoryNameString
comment: nil
changed: nil
!
variableByteSubclass: classNameString
instanceVariableNames: stringInstVarNames
classVariableNames: stringOfClassVarNames
poolDictionaries: stringOfPoolNames
category: categoryNameString
| meta |
KernelInitialized ifFalse: [ ^nil ].
self isVariable & (self isPointers | self isWords)
ifTrue: [ ^self error: 'Cannot create variable byte subclass from
non-byte parent class' ].
meta _ self metaclassFor: classNameString.
^meta name: classNameString
environment: Smalltalk
subclassOf: self
instanceVariableNames: stringInstVarNames
variable: true
words: false
pointers: false
classVariableNames: stringOfClassVarNames
poolDictionaries: stringOfPoolNames
category: categoryNameString
comment: nil
changed: nil
! !
!Class methodsFor: 'printing'!
printOn: aStream
self name printOn: aStream
!
storeOn: aStream
self printOn: aStream
! !
!Class methodsFor: 'private'!
setClassVariables: aDictionary
classVariables _ aDictionary
!
setSharedPools: aDictionary
sharedPools _ aDictionary
!
metaclassFor: classNameString
| className class |
className _ classNameString asSymbol.
class _ Smalltalk at: className
ifAbsent: [ nil ].
class isNil
ifTrue: [ ^Metaclass subclassOf: self class ].
^class class
! !